package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.service.ClasswithService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @auther wangchenghao
 * @date 2020/7/31
 **/
@Controller
@ResponseBody
@RequestMapping("userclass")
public class UserclassController {
    @Autowired
    ClasswithService classwithService;

    @ApiOperation("搜索用户所在班级")
    @RequestMapping(value = "/getUserClass", method = {RequestMethod.GET})
    public BaseModel getUserClass(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id,
                                  @ModelAttribute PageQueryModel pageQueryModel
    ) throws Exception {
        BaseModel model = new BaseModel();
        classwithService.queryallbyuser_id(user_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("搜索老师所在班级")
    @RequestMapping(value = "/getTeacherClass", method = {RequestMethod.GET})
    public BaseModel getTeacherClass(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id,
                                  @ModelAttribute PageQueryModel pageQueryModel
    ) throws Exception {
        BaseModel model = new BaseModel();
        classwithService.queryAllByUserId(user_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("用户加入班级")
    @RequestMapping(value = "/joinClass", method = {RequestMethod.PUT})
    public BaseModel joinClass(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id,
                               @ApiParam("班级id") @RequestParam(value = "class_id", required = true) int class_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        classwithService.joinclass(user_id, class_id, model);
        return model;
    }

    @ApiOperation("用户退出班级")
    @RequestMapping(value = "/quitClass", method = {RequestMethod.DELETE})
    public BaseModel quitClass(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id,
                               @ApiParam("班级id") @RequestParam(value = "class_id", required = true) int class_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        classwithService.quitclass(user_id, class_id, model);
        return model;
    }

}
